import time

import ddddocr
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:/Users/20486/AppData/Local/Google/Chrome/User Data/Default")
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options)
driver.maximize_window()

driver.get("https://www.bjcourt.gov.cn/cpws/index.htm?st=1&q=&sxnflx=0&prompt=&dsrName=&ajmc=&ajlb=&jbfyId=1&zscq=&ay=&ah=&cwslbmc=&startCprq=2021-01-04&endCprq=2021-01-08&startFbrq=&endFbrq=&page=11")
time.sleep(3)

# picture = driver.find_element("xpath", "//img[@id='yzmImg']").get_attribute('src')
# print(picture)
picture = driver.find_element("xpath", "//img[@id='yzmImg']").screenshot("yzm.png")
ocr = ddddocr.DdddOcr()  # 切换为第二套ocr模型

image = open("yzm.png", "rb").read()
result = ocr.classification(image, png_fix=True)
print(result)
element_input = driver.find_element("xpath", "//input[@id='yzmInput']").send_keys(result)
driver.find_element("xpath", "//a[@id='loginBtn']/span").click()
time.sleep(5)
